#!/usr/bin/python
#coding=utf-8
'''
    3.15. Converting Strings into Datetimes
    3.16. Manipulating Dates Involving Time Zones
'''
from datetime import datetime
text = '2012-09-20'
y = datetime.strptime(text, '%Y-%m-%d')
z = datetime.now()
diff = z - y
print(diff)

nice_z = datetime.strftime(z, '%A %B %d, %Y')
print(nice_z)

from datetime import datetime
def parse_ymd(s):
    year_s, mon_s, day_s = s.split('-')
    return datetime(int(year_s), int(mon_s), int(day_s))

a = parse_ymd('2002-01-01')
print(a)

# 3.16. Manipulating Dates Involving Time Zones
from datetime import timedelta
from pytz import timezone
d = datetime(2012, 12, 21, 9, 30, 0)
print(d)

# Localize the date for Chicago
central = timezone('US/Central')
loc_d = central.localize(d)
print(loc_d)

bang_d = loc_d.astimezone(timezone('Asia/Kolkata'))
print(bang_d)

import pytz
utc_d = loc_d.astimezone(pytz.utc)
later_utc = utc_d + timedelta(minutes=30)
print(later_utc.astimezone(central))

print(pytz.country_timezones['IN'])